import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/res/lf_double_ext.dart';
import 'package:largefriends/res/strings/lf_strings.dart';
import 'package:largefriends/widgets/lf_app_bar.dart';
import 'package:largefriends/widgets/lf_text_filed.dart';

import '../../res/lf_color.dart';
import '../../res/lf_fonts.dart';
import '../../res/lf_text_style.dart';
import '../../widgets/lf_auto_complete.dart';
import '../../widgets/lf_button.dart';
import '../../widgets/lf_text_label_filed.dart';
import '../lf_forget_password/lf_forget_password_logic.dart';
import 'lf_change_email_logic.dart';

class LfChangeEmailPage extends StatefulWidget {
  const LfChangeEmailPage({super.key});

  @override
  State<LfChangeEmailPage> createState() => _LfChangeEmailPageState();
}

class _LfChangeEmailPageState extends State<LfChangeEmailPage> {
  final logic = Get.put(LfChangeEmailLogic());

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Scaffold(
          appBar: lfAppBar(
              title: 'Change Email',
              leadingCallback: () {
                Get.back();
              }),
          body: Container(
              padding: REdgeInsets.symmetric(horizontal: 16.w),
              height: ScreenUtil().screenHeight,
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    Align(
                      alignment: Alignment.topLeft,
                      child: Text(
                        'Current Email',
                        style: lfTextStyle(
                            sp: 17.sp,
                            fontFamily: fontBold,
                            color: color514F62),
                      ),
                    ),
                    5.h.sbh,
                    Align(
                      alignment: Alignment.topLeft,
                      child: Text(
                        logic.authService.currentAccount!.email ?? "",
                        style: lfTextStyle(
                            sp: 15.sp,
                            fontFamily: fontRegular,
                            color: color514F62),
                      ),
                    ),
                    20.h.sbh,
                    autoCompleteWidget(
                        onSelected: (String value) {
                          logic.newEmail.value = value;
                        },
                        hintText: "New Email",
                        focusNode: logic.emailFocusNode,
                        onChanged: (String value) {
                          logic.newEmail.value = value;
                        },
                        controller: logic.emailTextEditingController),
                    20.h.sbh,
                    autoCompleteWidget(
                        onSelected: (String value) {
                          logic.confirmEmail.value = value;
                        },
                        hintText: "Confirm New Email",
                        focusNode: logic.confirmEmailFocusNode,
                        onChanged: (String value) {
                          logic.confirmEmail.value = value;
                        },
                        controller: logic.confirmEmailTextEditingController),
                    20.h.sbh,
                    LfTextLabelFiled(
                      textEditingController: logic.passwordTextEditingController,
                      isPassword: true,
                      focusNode: logic.passwordFocusNode,
                      inputFormatters: [
                        LengthLimitingTextInputFormatter(16),
                        FilteringTextInputFormatter.allow(
                          RegExp('[A-Za-z0-9]'),
                        )
                      ],
                      prefixIcon: Icon(
                        Icons.lock,
                        color: colorFF007F,
                        size: 20.w,
                      ),
                      hintText: 'Password',
                      onChanged: (value) {
                        logic.password.value = value;
                      },
                    ),
                    30.h.sbh,
                    Align(
                      alignment: Alignment.topLeft,
                      child: InkWell(
                        child: Text("Forget Password?",
                            style: lfTextStyle(
                              sp: 15.sp,
                              fontFamily: fontBold,
                              color: color514F62,
                              decoration: TextDecoration.underline,
                            )),
                        onTap: () {
                          toForgetPassword(
                              email: logic.authService.currentAccount!.email ??
                                  "");
                        },
                      ),
                    ),
                    80.h.sbh,
                    Padding(
                      padding: EdgeInsets.symmetric(horizontal: 20.w),
                      child: Obx(
                        () => LfButton(
                          enabled: logic.enableContinue,
                          text: strContinue.tr,
                          onPress: () {
                            logic.changeEmail();
                          },
                        ),
                      ),
                    )
                  ],
                ),
              )),
        ),
        onWillPop: () async {
          Get.back();
          return false;
        });
  }
}
